package com.boxedinsoftware.betamax.dialer;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.view.KeyEvent;

import android.widget.Toast;



public class dialNowPrefs extends PreferenceActivity {
	SharedPreferences preferences; 
	private PreferenceScreen screen;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    addPreferencesFromResource(R.xml.prefs);
	    
	    
	    screen = getPreferenceScreen();
	    preferences = PreferenceManager.getDefaultSharedPreferences(this);
	    
	    Preference x = screen.findPreference("getAcc");
	    x.setOnPreferenceClickListener(new OnPreferenceClickListener(){

			public boolean onPreferenceClick(Preference preference) {
				String provider = preferences.getString("betamaxProvider", "0");
				int providerInt;
				String url = null;
				try{
				
				providerInt = new Integer(Integer.parseInt(provider));
				}
				catch (Exception e)
				{
					
					providerInt = 0;
					
				}
				
				if(providerInt == 0)
					url = null;
				if(providerInt == 1)
				url = "http://www.12voip.com/en/geo.html";	
				if(providerInt == 2)
				url = "http://www.actionvoip.com/en/geo.html";
				if(providerInt == 3)
				url = null;
				if(providerInt == 4)
				url = "http://www.calleasy.com/en/accessnumbers.html";
				if(providerInt == 5)
				url = "http://www.callingcredit.com/en/instructions.html";
				if(providerInt == 6)
				url = "http://www.cheapvoip.com/en/geo.html";
				if(providerInt == 7)
				url = "http://www.dialnow.com/en/accessnumbers.html";
				if(providerInt == 8)
				url = "http://www.freecall.com/en/geo.html";	
				if(providerInt == 9)
				url = "http://www.internetcalls.com/en/geo.html";
				if(providerInt == 10)
				url = "http://www.intervoip.com/en/geo.html";
				if(providerInt == 11)
			    url = "http://www.jumblo.com/en/geo.html";
				if(providerInt == 12)
					url = "http://www.justvoip.com/en/geo.html";
				if(providerInt == 13)
					url = "http://www.lowratevoip.com/en/geo.html";
				if(providerInt == 14)
					url = "http://www.netappel.fr/fr/geo.html";
				if(providerInt == 15)
					url = "http://www.nonoh.net/en/geo.html";
				if(providerInt == 16)
					url = "http://www.poivy.com/en/geo.html";
				if(providerInt == 17)
					url = "http://www.powervoip.com/en/geo.html";
				if(providerInt == 18)
					url = "http://www.rynga.com/en/geo.html";
				if(providerInt == 19)
					url = "http://www.sipdiscount.com/en/geo.html";
				if(providerInt == 20)
					url = "http://www.smartvoip.com/en/geo.html";
				if(providerInt == 21)
					url = "http://www.smsdiscount.com/en/geo.html";
				if(providerInt == 22)
					url = "http://www.smslisto.com/en/geo.html";
				if(providerInt == 23)
					url = "http://www.sparvoip.de/de/geo.html";
				if(providerInt == 24)
					url = "http://www.voipblast.com/en/geo.html";
				if(providerInt == 25)
					url = "http://www.voipbuster.com/en/geo.html";
				if(providerInt == 26)
					url = "http://www.voipbusterpro.com/en/geo.html";
				if(providerInt == 27)
					url = "http://www.voipcheap.co.uk/en/geo.html";
				if(providerInt == 28)
					url = "http://www.voipcheap.com/en/geo.html";
				if(providerInt == 29)
					url = "http://www.voipdiscount.com/en/geo.html";
				if(providerInt == 30)
					url = "http://www.voipgain.com/en/geo.html";
				if(providerInt == 31)
					url = null;
				if(providerInt == 32)
					url = "http://www.voipraider.com/en/geo.html";
				if(providerInt == 33)
					url = "http://www.voipstunt.com/en/geo.html";
				if(providerInt == 34)
					url = "http://www.voipwise.com/en/geo.html";
				if(providerInt == 35)
					url = null;
				if(providerInt == 36)
					url = "http://www.webcalldirect.com/en/geo.html";
				
				
					
				
				
				if(url == null)
				{
					Toast.makeText(getApplicationContext(), "Please choose a provider first.", Toast.LENGTH_LONG).show();
				}
				else
				{
				Intent i = new Intent(Intent.ACTION_VIEW);
				i.setData(Uri.parse(url));
				startActivity(i);
				}
				return false;
			}
	    	
	    	
	    	
	    	
	    	
	    });
	    
	   
	    
	    
	}
	
	 @Override
	    public boolean onKeyDown(int keyCode, KeyEvent event) {
	        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
	        	this.getIntent().putExtra("refresh", 1);
	        	setResult(Activity.RESULT_OK, null);
	    	    finish();
	        
	        
	        }
	        return super.onKeyDown(keyCode, event);
	    }
	

}